home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Selection ƒ 2.5 / list-col < prev    next >
Encoding:
Text File  |  1994-11-06  |  2.3 KB  |  119 lines  |  [TEXT/MSET]

  1.  \ 30Aug94 dbh added focus: response so key: messages are sent.
  2.  \ 28Oct94 dbh updated to 2.5 syntax 
  3.  
  4. (*
  5.  
  6. *** DESCRIPTION
  7.  
  8. A 1 column list, a list-col is based on the ListManager.  This is a selection
  9. protocol class.  We treat the list as if it were a 1-dimensional array and
  10. use the access methods to: and at: in the expected fashion, with the address
  11. and length of the string being the data.
  12.  
  13. *)
  14.  
  15. :class list-col super{ ListManager }
  16.  
  17. :m classinit:
  18.     0 1 put: theBounds        \ start with  0 rows ( 1 column of course)
  19.     50 20 150 100 put: rView
  20.     50 put: MaxDataLen
  21.     false put: scrollHoriz
  22.     true put: scrollVert
  23.     ;m
  24.  
  25. :m at:    ( row# -- addr len )
  26.     0 at: super  ;m  \ will return len = actual length
  27.  
  28. :m to:    ( addr len row# -- )
  29.     0 to: super ;m
  30.  
  31. :m add:    { addr len \ row# -- }
  32.     \ adds one cell to the end of the list with the given text
  33.     word0    \ room for result
  34.     1 \ count
  35.     9999 pack \ rowNum, make it large so new last rows will always be added
  36.     get: ListHandle call LAddRow i->l -> row#
  37.     addr len row# to: self
  38.     row# select: [self]
  39.     show: self
  40.     row# deselect: [self]
  41.     ;m
  42.  
  43. :m delete:    { row# -- }    \ deletes the given cell
  44.     1 makeint ( count) row# ( rowNum) makeint
  45.     get: ListHandle call LDelRow ;m
  46.  
  47. :m selected?:    ( row# -- b )    \ true if given cell is selected
  48.     0 false LGetSelect: self ;m
  49.  
  50. :m select:    ( row# -- )
  51.     0 select: super ;m
  52.  
  53. :m deselect:  ( row# -- )
  54.     0 deselect: super ;m
  55.  
  56. :m next:    { row#1 -- row#2 t | f }
  57.     \ given a cell row#, return the next selected cell row# under true if
  58.     \ there is a selected cell after row#1, if no more selected cells return false
  59.     row#1 0 true LGetSelect: self
  60.     IF
  61.         getrow#: theCell true
  62.     ELSE
  63.         false
  64.     THEN ;m
  65.  
  66. :m deleteSel:    { \ row# -- }    \ delete only the selected rows
  67.     false dodraw: self
  68.     0 -> row#
  69.     row# selected?: self IF row# delete: self THEN
  70.     BEGIN
  71.         row# next: self
  72.     WHILE
  73.         ( row#2 ) -> row#
  74.         row# delete: self
  75.     REPEAT
  76.     true dodraw: self
  77. ;m
  78.  
  79. :m deleteAll:    \ delete all cells
  80.     BEGIN
  81.         #rows: self        \ while we have at least one row
  82.     WHILE
  83.         0 delete: self    \ delete it
  84.     REPEAT ;m
  85.  
  86. :m key:  ( char -- )
  87.     CASE
  88.         8 ( delete) OF deleteSel: self ENDOF
  89.     ENDCASE ;m
  90.  
  91. :m clear:
  92.     deleteSel: self ;m
  93.  
  94. :m focus?: ( -- true )
  95.     true ;m
  96.     
  97. ;class
  98.  
  99. endload
  100.  
  101. *** EXAMPLE USE
  102.  
  103. selwindow w
  104. test: w
  105.  
  106. list-col l
  107. l add: w
  108.  
  109. " hello" add: l
  110. " world" add: l
  111. " trains" add: l
  112. " boats" add: l
  113. " planes" add: l
  114. " hello" add: l
  115. " world" add: l
  116. " trains" add: l
  117. " boats" add: l
  118. " planes" add: l
  119.